
# define the config
SHELL = /bin/sh
CC = gcc
CXX = g++

CFAGS  := -Wall -Werror -g -O2
RM := rm -f

LIBS = mylib.dll

SRCEXTS := .c   #.cpp .C

SRC = $(wildcard $(addprefix *,$(SRCEXTS)))
OBJS = $(foreach x,$(SRCEXTS),$(patsubst %$(x),%.o,$(filter %$(x),\
	   $(SRC)))) 

.PHONY: all clean rebuild debug


all:version $(LIBS)


version:
	@$(CC) --version

#--------------------------------------
%.o:%.c
	$(CC) -c $(CFAGS) $<
%.o:%.cpp
	$(CXX) $(CFAGS) $(INC_PATH) -c $<
%.o:%.C
	$(CXX) $(CFAGS) $(INC_PATH) -c $<
#--------------------------------------	
	
$(LIBS):$(OBJS)
	@echo creating $(LIBS)...
ifeq ($(strip $(SRCEXTS)), .c) # C file 
	$(CC) -o $@ -shared $^ 
else
	$(CXX) -o $@ -shared $^ 
endif

clean:
	@echo deleting *.o *.dll *.bak...
	$(RM) *.o *.dll *.bak
	
rebuild: clean all

debug:
	@echo $(SRC)
	@echo $(OBJS)
	
